package com.os.sys.repository;

import com.os.sys.model.T_SYS_Param;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2017/6/14.
 */
public interface ParamRepository extends PagingAndSortingRepository<T_SYS_Param, Long> {

    @Query("select t from T_SYS_Param t where t.paramKey=?1 and t.parentId<>0l")
    List<T_SYS_Param> findDataValue(String key);
    @Query("select t from T_SYS_Param t where t.paramKey=?1 and t.parentId<>0l and t.enable=1")
    List<T_SYS_Param> findDataValueForUser(String paramKey);
    List<T_SYS_Param> findByEnable(int enable);
    List<T_SYS_Param> findByParentId(Long parentId);

    @Transactional
    @Modifying
    @Query("delete from T_SYS_Param t where t.paramKey=?1 and t.parentId<>0l")
    int deleteDataValues(String paramKey);
}
